package com.cxc.java8;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class MethodRefrence  {

    private static <T> void  useConsumer(Consumer<T> consumer,T t){
        consumer.accept(t);
        consumer.accept(t);

    }

    public static void main(String[] args) {
       /* Consumer<String> consumer =  s-> System.out.println(s);
        useConsumer(consumer,"hello");*/
        useConsumer(s-> System.out.println(s),"hello");
        useConsumer(System.out::println,"hi,cxc!");

        List<Apple> apples = Arrays.asList(new Apple("abb", 125),new Apple("green", 123));
        apples.sort((s1,s2)->s1.getColor().compareTo(s2.getColor()));
        System.out.println(apples);

        apples.stream().forEach(System.out::println);

        int value =  Integer.parseInt("123");

        Function<String,Integer> f =  Integer::parseInt;
        Integer result = f.apply("1234");
        System.out.println(result);

        BiFunction<String, Integer, Character> f2 = String::charAt;
        Character result1 = f2.apply("cxc", 2);
        System.out.println(result1);

        Function<Integer, Character> f3 = new String("cxc2")::charAt;
        Character resutl2 = f3.apply(3);
        System.out.println(resutl2);

        Supplier<String> supplier = String::new;
        String s = supplier.get();
        System.out.println(s);

        System.out.println("-----------------------------");
        BiFunction<String,Long,Apple> appleBiFunction =  Apple::new;
        Apple resultApple = appleBiFunction.apply("red", 100L);
        System.out.println(resultApple);


        ThreeFunction<String, Long, String, ComplexApple> threeFunction = ComplexApple::new;
        ComplexApple complexApple = threeFunction.apply("Green", 123L, "FuShi");
        System.out.println(complexApple);


        List<Apple> list2 = Arrays.asList(new Apple("abc", 123), new Apple("Green", 110), new Apple("red", 123));

        System.out.println(list2);
        list2.sort(Comparator.comparing(Apple::getColor));
        System.out.println(list2);

    }
}
